package com.epalmpay.controller.channel.member;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.memberGrade.MemberFeeSettingList;
import com.epalmpay.dto.memberGrade.MemberFeeSettingOutDTO;
import com.epalmpay.entity.MemberFee;
import com.epalmpay.service.member.IMemberFeeSettingService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 说明：会员等级费率设置
 * 创建人：gwn
 * 创建时间：2017-05-9
 */
@Controller
@RequestMapping(value="/merchant/member")
public class MemberGradeFeeSettingController extends BaseController{

    @Resource
    private IMemberFeeSettingService memberFeeSettingService;

    @RequestMapping(value="/feeSettingList")
    @ResponseBody
    public MemberFeeSettingList memberFeeSettingList( MemberFee memberFee){
        MemberFeeSettingList memberFeeSettingList=new MemberFeeSettingList();
        try {

            List<MemberFee> memberFeeList=memberFeeSettingService.memberFeeSettingList(memberFee);
            memberFeeSettingList.setMemberFeeList(memberFeeList);
            memberFeeSettingList.setErrorCode(Rescode.SUCCESS, "处理成功");
            return memberFeeSettingList;

        }
        catch (ApplicationException ae) {
            memberFeeSettingList.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberFeeSettingList.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }


        return memberFeeSettingList;

    }


    @RequestMapping(value="/getFeeSettingById")
    @ResponseBody
    public MemberFeeSettingOutDTO GetFeeSettingById(@RequestBody MemberFee memberFee){
        MemberFeeSettingOutDTO memberFeeSettingOutDTO=new MemberFeeSettingOutDTO();
        try {

            memberFeeSettingOutDTO=memberFeeSettingService.GetFeeSettingById(memberFee);
            memberFeeSettingOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return memberFeeSettingOutDTO;

        }
        catch (ApplicationException ae) {
            memberFeeSettingOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberFeeSettingOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }


        return memberFeeSettingOutDTO;

    }


    @RequestMapping(value="/updateFeeSettingById")
    @ResponseBody
    public MemberFeeSettingOutDTO UpdateFeeSettingById(@RequestBody MemberFee memberFee){
        MemberFeeSettingOutDTO memberFeeSettingOutDTO=new MemberFeeSettingOutDTO();
        try {

            memberFeeSettingOutDTO=memberFeeSettingService.UpdateFeeSettingById(memberFee);
//            memberFeeSettingOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return memberFeeSettingOutDTO;

        }
        catch (ApplicationException ae) {
            memberFeeSettingOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberFeeSettingOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }


        return memberFeeSettingOutDTO;

    }

    @RequestMapping(value="/setFeeStatusById")
    @ResponseBody
    public MemberFeeSettingOutDTO SetFeeStatusById(@RequestBody MemberFee memberFee){
        MemberFeeSettingOutDTO memberFeeSettingOutDTO=new MemberFeeSettingOutDTO();
        try {

            memberFeeSettingOutDTO=memberFeeSettingService.SetFeeStatusById(memberFee);
//            memberFeeSettingOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return memberFeeSettingOutDTO;

        }
        catch (ApplicationException ae) {
            memberFeeSettingOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberFeeSettingOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }


        return memberFeeSettingOutDTO;

    }
}
